package model;

import weka.core.Instance;
import weka.core.Instances;


public class Article {

	
	
/*
	private String type;
	private String donnees;
	
	
	private ArrayList <String> motChoisis;
	private ArrayList <String> phrases;
	private ArrayList <String> paragraphes;

	private HashMap<String, ArrayList<Integer>> matOcc = new HashMap<String, ArrayList<Integer>> ();
	
	public Article (){
		this.type = "no type.";
		this.donnees = "no data";
		/*
		this.freqMot = new HashMap<String, String>();
		this.freqParagraphe = new HashMap<String, String>();
		this.freqPhrase = new HashMap<String, String>();
		
		this.motChoisis = new ArrayList<String>();
		this.paragraphes = new ArrayList<String>();
		this.phrases = new ArrayList<String>();
	}

	/** 
	 * Lis le fichier file
	 * @param file
	 * @throws IOException
	 
	public void CreateArticles(File file) throws IOException {

		this.type = file.getParentFile().getName();
		BufferedReader r = new BufferedReader(new FileReader(file));
		String scan = "";
		int value = 0;
		while ((value = r.read()) != -1){
			char c = (char)value;
			scan += c;
		}
		this.donnees = scan.replaceAll("[=]", "").toLowerCase();

		if(r!=null)
			r.close();
	}


	/**
	 * Retourne le nombre de mots dans le fichier
	 * @return Integer
	 
	public int nbWords () {
		String temp = donnees.replaceAll("[\\n]", " ");
		String[] splitter = temp.replaceAll("[.,?!:;/\"]()","").split(" ");

		return splitter.length;
	}

	/**
	 * Retourne le nombre de phrases dans le fichier
	 * @return Integer
	 
	public int nbPhrases () {
		int cpt = 0;
		for (int i = 0; i<donnees.length(); i++) 
			if (donnees.charAt(i) == '.' || donnees.charAt(i) == '?' || donnees.charAt(i) == '!')
				cpt++;		
		return cpt;
	}

	/**
	 * Retourne le nombre de paragraphes dans le fichier
	 * @return Integer
	 
	public int nbParagraphes () {
		String[] splitter = donnees.replaceAll("[.,?!:;/\"]()","").split("\n");
		return splitter.length;
	}

	/**
	 * Retourne une HashMap avec pour clef le mot et pour value la frequence
	 * Les mots fréquents sont arbitrairement choisi (mot de taille > 2) etc.
	 * @return HashMap<String, Float>
	 
	public String frequentWords (String param) {

		HashMap<String, Integer> freq = new HashMap<String, Integer>();
		HashMap<String, String> freqString = new HashMap<String, String>();

		String visuel = "";
		// Précision à 3 chiffres après la virgule pour la fréquence
		DecimalFormat df = new DecimalFormat("#.###");
		String temp = donnees.toLowerCase().replaceAll("[\\n]",  " ");
		String[] splitter = temp.replaceAll("[.,?!:;/()\"]","").split(" ");

		System.out.println("phrases : " + nbPhrases() + " mot : " + nbWords() + " paragraphes : " + nbParagraphes());

		switch (param){
		case "mot":		
			for(int i=0; i<splitter.length; i++){
				temp = splitter[i];
				if (freq.containsKey(temp))
					freq.put(temp, freq.get(temp)+1);
				else 
					freq.put(temp, 1);
			}

			String tmp = "";


			for(Entry<String, Integer> entry : freq.entrySet()) {

				if(entry.getValue() > 1 && entry.getKey().length() > 2){
					tmp = df.format((float)entry.getValue() / nbWords());
					freqString.put(entry.getKey(),tmp);
				}
			}

		//	this.freqMot= freqString; 

			for(Entry<String, String> entry : freqString.entrySet())
				visuel = visuel + entry.getKey() + " : " + entry.getValue() + "\n";
			break;

		case "phrases":		
			freq = new HashMap<String, Integer>();
			freqString = new HashMap<String, String>();
			temp = donnees.toLowerCase().replaceAll("[\\n]",  " ");
			temp = temp.replaceAll("[,?!:;/()\"]","");
			phrases = new ArrayList<String>();
			String texte = "";

			for (int i = 0; i<temp.length(); i++) {
				while ((temp.charAt(i) != '.' || temp.charAt(i) != '?' || temp.charAt(i) != '!') && i <temp.length()-1) {
					texte += temp.charAt(i);
					i++;
				}
				phrases.add(texte);
				texte = "";
			}

			int nbPhrases = 1;

			for (String it : phrases) {
				splitter = it.split(" ");
				for(int i=0; i<splitter.length; i++){
					temp = splitter[i];
					if (freq.containsKey(temp) && freq.get(temp) < nbPhrases)
						freq.put(temp, freq.get(temp)+1);
					else if (!freq.containsKey(temp))
						freq.put(temp, 1);
				}
				nbPhrases++;
			}

			for(Entry<String, Integer> entry : freq.entrySet()) {

				if(entry.getValue() > 1 && entry.getKey().length() > 2){
					temp = df.format((float)entry.getValue() / nbPhrases());
					freqString.put(entry.getKey(),temp);
				}
			}

	//		this.freqPhrase = freqString; 		

			for(Entry<String, String> entry : freqString.entrySet())
				visuel = visuel + entry.getKey() + " : " + entry.getValue() + "\n";
			break;

		case "paragraphes" :
			freq = new HashMap<String, Integer>();
			freqString = new HashMap<String, String>();
			paragraphes = new ArrayList<String>();

			temp = donnees.toLowerCase().replaceAll("[\\n]",  " ");
			temp = temp.replaceAll("[,?!:;/()\"]","");
			texte = "";
			splitter = donnees.replaceAll("[.,?!:;/\"]()","").split("\n");

			for (int i = 0; i<splitter.length; i++) {
				String[] splitter2 = splitter[i].split(" ");
				for (int j = 0; j<splitter2.length; j++)
					if(freq.containsKey(splitter2[j]) && freq.get(splitter2[j])< i)
						freq.put(splitter2[j], freq.get(splitter2[j])+1 );
					else	
						freq.put(splitter2[j], 1);
			}

			for (String ss : splitter)
				this.paragraphes.add(ss);

			for(Entry<String, Integer> entry : freq.entrySet()) {

				if(entry.getValue() > 1 && entry.getKey().length() > 2){
					temp = df.format((float)entry.getValue() / nbParagraphes());
					freqString.put(entry.getKey(),temp);
				}
			}

		//	this.freqParagraphe = freqString; 		
			for(Entry<String, String> entry : freqString.entrySet())
				visuel = visuel + entry.getKey() + " : " + entry.getValue() + "\n";		
			break;
		default :
			visuel = "no data";
		}
		return visuel;

	}

	/**
	 * Permet de remettre à jour les valeurs selon un changement de paramètres
	 * @param param
	 
	public void refresh (String param)  {
		HashMap<String, Integer> freq = new HashMap<String, Integer>();
		HashMap<String, String> freqString = new HashMap<String, String>();

		String visuel = "";
		// Précision à 3 chiffres après la virgule pour la fréquence
		DecimalFormat df = new DecimalFormat("#.###");
		String temp = donnees.toLowerCase().replaceAll("[\\n]",  " ");
		String[] splitter = temp.replaceAll("[.,?!:;/()\"]","").split(" ");

		switch (param){
		case "mot":		
			for(int i=0; i<splitter.length; i++){
				temp = splitter[i];
				if (freq.containsKey(temp))
					freq.put(temp, freq.get(temp)+1);
				else 
					freq.put(temp, 1);
			}

			String tmp = "";


			for(Entry<String, Integer> entry : freq.entrySet()) {

				if(entry.getValue() > 1 && entry.getKey().length() > 2){
					tmp = df.format((float)entry.getValue() / nbWords());
					freqString.put(entry.getKey(),tmp);
				}
			}

	//		this.freqMot= freqString; 

			for(Entry<String, String> entry : freqString.entrySet())
				visuel = visuel + entry.getKey() + " : " + entry.getValue() + "\n";
			break;

		case "phrases":		
			freq = new HashMap<String, Integer>();
			freqString = new HashMap<String, String>();
			temp = donnees.toLowerCase().replaceAll("[\\n]",  " ");
			temp = temp.replaceAll("[,?!:;/()\"]","");
			ArrayList<String> phrases = new ArrayList<String>();
			String texte = "";
			for (int i = 0; i<temp.length(); i++) {
				while (temp.charAt(i) != '.' && i <temp.length()-1) {
					texte += temp.charAt(i);
					i++;

				}
				phrases.add(texte);
				texte = "";
			}

			int nbPhrases = 0;

			this.phrases = phrases;

			for (String it : phrases) {
				splitter = it.split(" ");
				for(int i=0; i<splitter.length; i++){
					temp = splitter[i];
					if (freq.containsKey(temp) && freq.get(temp) < nbPhrases)
						freq.put(temp, freq.get(temp)+1);
					else if (!freq.containsKey(temp))
						freq.put(temp, 1);
				}
				nbPhrases++;
			}

			for(Entry<String, Integer> entry : freq.entrySet()) {

				if(entry.getValue() > 1 && entry.getKey().length() > 2){
					temp = df.format((float)entry.getValue() / nbPhrases());
					freqString.put(entry.getKey(),temp);
				}
			}

		//	this.freqPhrase = freqString; 		

			for(Entry<String, String> entry : freqString.entrySet())
				visuel = visuel + entry.getKey() + " : " + entry.getValue() + "\n";
			break;

		case "paragraphes" :
			freq = new HashMap<String, Integer>();
			freqString = new HashMap<String, String>();

			temp = donnees.toLowerCase().replaceAll("[\\n]",  " ");
			temp = temp.replaceAll("[,?!:;/()\"]","");
			texte = "";
			splitter = donnees.replaceAll("[.,?!:;/\"]()","").split("\n");

			for (int i = 0; i<splitter.length; i++) {
				String[] splitter2 = splitter[i].split(" ");
				for (int j = 0; j<splitter2.length; j++)
					if(freq.containsKey(splitter2[j]) && freq.get(splitter2[j])< i)
						freq.put(splitter2[j], freq.get(splitter2[j])+1 );
					else	
						freq.put(splitter2[j], 1);
			}

			for (String ss : splitter)
				this.paragraphes.add(ss);

			for(Entry<String, Integer> entry : freq.entrySet()) {

				if(entry.getValue() > 1 && entry.getKey().length() > 2){
					temp = df.format((float)entry.getValue() / nbParagraphes());
					freqString.put(entry.getKey(),temp);
				}
			}

	//		this.freqParagraphe = freqString; 		
			for(Entry<String, String> entry : freqString.entrySet())
				visuel = visuel + entry.getKey() + " : " + entry.getValue() + "\n";		
			break;
		default :
			visuel = "no data";
		}
	}

	public ArrayList<String> getPhrases() {
		return phrases;
	}


	public void setPhrases(ArrayList<String> phrases) {
		this.phrases = phrases;
	}


	public ArrayList<String> getParagraphes() {
		return paragraphes;
	}


	public void setParagraphes(ArrayList<String> paragraphes) {
		this.paragraphes = paragraphes;
	}

/*
	public HashMap<String, String> getFreqMot() {
		return freqMot;
	}


	public void setFreqMot(HashMap<String, String> freqMot) {
		this.freqMot = freqMot;
	}


	public HashMap<String, String> getFreqPhrase() {
		return freqPhrase;
	}


	public void setFreqPhrase(HashMap<String, String> freqPhrase) {
		this.freqPhrase = freqPhrase;
	}


	public HashMap<String, String> getFreqParagraphe() {
		return freqParagraphe;
	}


	public void setFreqParagraphe(HashMap<String, String> freqParagraphe) {
		this.freqParagraphe = freqParagraphe;
	}


	public void setType(String type) {
		this.type = type;
	}


	public void setDonnees(String donnees) {
		this.donnees = donnees;
	}


	public String getType() {
		return this.type;
	}

	public String getDonnees(){
		return this.donnees;
	}

	public int getOccurence (String texte, String mot){
		String[] splitter = texte.split(" ");
		int cpt = 0;
		for (String i : splitter){
			if (i.equals(mot))
				cpt++;
		}
		return cpt;
	}
/**
 * ArrayList tmp correspond au différentes valeurs d'un mot selon la phrase s2
 * @param param
 
	public void createMatrixOcc (String param) {
		this.matOcc = new HashMap<String, ArrayList<Integer>> ();
		ArrayList<Integer> tmp = new ArrayList<Integer>();
		switch (param){
		case "phrases":
			for (String s1 : this.motChoisis){
				for (String s2 : this.phrases){
					tmp.add(getOccurence(s2,s1));
				}
				matOcc.put(s1, tmp);
				tmp.clear();
			}
		case "paragraphes":
			for (String s1 : this.motChoisis){
				for (String s2 : this.paragraphes){
					tmp.add(getOccurence(s2,s1));
				}
				matOcc.put(s1, tmp);
				tmp.clear();
			}
		}
	}
	
	public void afficheMatriceOcc () {
		
	}
	*/
}
